package org.example._01_game;

import java.awt.*;
import java.io.*;

/**
 * 文字输入
 */
public class _01_FileTest {
    public static void main(String[] args) throws Exception  {
        // 写入文本内容
        String content = "Hello World!";
        // 创建txt文件
        String os = System.getProperty("os.name").toLowerCase();
        String filePath = "test.txt";
        if (os.contains("win")) {
            filePath = "C:\\Temp\\" + filePath;
        } else if (os.contains("mac")) {
            filePath = "/Users/eddy/Desktop/" + filePath;
        }

        File file = new File(filePath);
        try {
            if (!file.exists()) {
                file.createNewFile();
            }
            /**
             * 字符流  文字
             */
            FileWriter fw = new FileWriter(file.getAbsoluteFile());
            BufferedWriter bw = new BufferedWriter(fw);
            bw.write(content);
            bw.close();

//            Runtime.getRuntime().exec("notepad.exe" + file.getAbsoluteFile());
            // 打开文件
            Desktop desktop = Desktop.getDesktop();
            desktop.open(file);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
